#include <stdio.h>
#include <string.h>

int change(char hex[]) {
    int num = 0;
    int i, digit;
    for (i = 0; i < strlen(hex); i++) {
        if (hex[i] >= '0' && hex[i] <= '9') {
            digit = hex[i] - '0';
        } else if (hex[i] >= 'a' && hex[i] <= 'f') {
            digit = hex[i] - 'a' + 10;
        } else if (hex[i] >= 'A' && hex[i] <= 'F') {
            digit = hex[i] - 'A' + 10;
        } else {
            printf("输入的不是有效的十六进制数！\n");
            return -1;
        }
        num = num * 16 + digit;
    }
    return num;
}

int main() {
    char hex[100];
    int num;
    printf("请输入一个十六进制数：");
    scanf("%s", hex);
    num = change(hex);
    if (num != -1) {
        printf("相应的十进制数为：%d\n", num);
    }
    return 0;
}